package com.huayun.plugin.materialSetting.controller;

import com.huayun.plugin.materialLibrary.domain.MaterialLibrary;
import com.huayun.plugin.materialSetting.domain.InstanceMaterialInfo;
import com.huayun.plugin.materialSetting.domain.PartDocumentInfo;
import com.huayun.plugin.materialSetting.service.PartMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/materialSetting")
public class PartMaterialController {
    @Autowired
    private PartMaterialService partMaterialService;

    @PostMapping("/getCurrentPartMaterialInfo")
    public ResponseEntity<List<MaterialLibrary>> getCurrentPartMaterialInfo(@RequestParam String partDocId) {
        List<MaterialLibrary> materialLibraryList = partMaterialService.getCurrentPartMaterialInfo(partDocId);
        return ResponseEntity.ok(materialLibraryList);
    }
    @PostMapping("/getInsMaterialInfoByDocInfos")
    public ResponseEntity<List<InstanceMaterialInfo>> getInsMaterialInfoByDocIds(@RequestBody List<PartDocumentInfo> docInfoList) {
        List<InstanceMaterialInfo> materialList = partMaterialService.getInsMaterialInfoByDocInfos(docInfoList);
        return ResponseEntity.ok(materialList);
    }

    @PostMapping("addMaterialItemToCurrentPart")
    public ResponseEntity<List<MaterialLibrary>> addMaterialItemToCurrentPart(@RequestParam String partDocId,
                                                                              @RequestParam String partDocName,
                                                                              @RequestParam List<String> materialNumbers){
        List<MaterialLibrary> materialLibraryList = partMaterialService.addMaterialItemToCurrentPart(partDocId,partDocName,materialNumbers);
        return ResponseEntity.ok(materialLibraryList);
    }

    @PostMapping("deleteMaterialItemToCurrentPart")
    public ResponseEntity<List<MaterialLibrary>> deleteMaterialItemToCurrentPart(@RequestParam String partDocId,
                                                                                 @RequestParam List<String> materialNumbers){
        List<MaterialLibrary> materialLibraryList = partMaterialService.deleteMaterialItemToCurrentPart(partDocId,materialNumbers);
        return ResponseEntity.ok(materialLibraryList);
    }
}
